/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chl.niclun.projectwebshop.nbp;

import edu.chl.niclun.projectwebshop.nbp.DataBase.Database;
import edu.chl.niclun.projectwebshop.nbp.Entities.Movie;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

/**
 *ControllerBean for the header
 * @author marjona
 */
@ManagedBean
@RequestScoped
public class HeaderControllerBean {

    @ManagedProperty(value = "#{showResultBackingBean}")
    private ShowResultBackingBean showResultBackingBean;
    
    
    private List<Movie> movies;
    private List<Movie> searchList;
    /** Creates a new instance of HeaderControllerBean */
    public HeaderControllerBean() {
        searchList = new ArrayList<Movie>();
    }
    
    //called when we use the search function in the header
    public void search(ActionEvent evt){
        movies = Database.getWebshopController().searchGenre(null);
        if(showResultBackingBean.getOption().equals((String) "actor")){   
            searchList = Database.getWebshopController().searchActor(showResultBackingBean.getSearchText());
            showResultBackingBean.setMovies(searchList);
        }
                
        else if(showResultBackingBean.getOption().equals((String) "title")){            
            searchList = Database.getWebshopController().searchTitle(showResultBackingBean.getSearchText());
            showResultBackingBean.setMovies(searchList);          
        }
    }
    //navigate
    public String navigate(){
        return "showResult";
    }
    //navigate to the homepage(index.xhtml)
    public String navigateToHomePage() {
        return "index";
    }

    public ShowResultBackingBean getShowResultBackingBean() {
        return showResultBackingBean;
    }

    public void setShowResultBackingBean(ShowResultBackingBean showResultBackingBean) {
        this.showResultBackingBean = showResultBackingBean;
    }

    public List<Movie> getSearchList() {
        return searchList;
    }

    public void setSearchList(List<Movie> searchList) {
        this.searchList = searchList;
    }

    public List<Movie> getMovies() {
        return movies;
    }

    public void setMovies(List<Movie> movies) {
        this.movies = movies;
    }
    
}
